let storageName = 'shoppingCartData';
let storage = {
  data: {

  },
  methods: {
    getAppShopId() {
      let shopInfo = getApp().globalData.shopInfo;
      if (shopInfo && shopInfo.shopId) {
        return shopInfo.shopId
      }
      return null;
    },
    // 更新本店铺本地购物车数据
    updateShoppingCartStorage(newData) {
      let data = wx.getStorageSync(storageName) || {},
        shopId = this.getAppShopId();
      data[shopId] = JSON.parse(JSON.stringify(newData));
      wx.setStorageSync(storageName, data);
    },
    // 获取本店铺本地购物车数据
    getShoppingCartStorage() {
      let data = wx.getStorageSync(storageName) || {},
        shopId = this.getAppShopId();
      return shopId ? (data[shopId] || []) : [];
    },
    // 删除此商铺本地购物车数据
    deleteShoppingCartStorage() {
      let data = wx.getStorageSync(storageName) || {},
        shopId = this.getAppShopId();
      if (shopId) {
        delete data[shopId]
      }
      wx.setStorageSync(storageName, data);
    }
  }
}

module.exports = {
  ...storage
}